
#include <msRegister.h>
#include <msTreeMapper.h>
#include <msUnitsManager.h>

using namespace atomism;

int main(int argc, char **argv) {
 
 std::map<std::string, msRegister::base_creator_fn>::iterator it;
 std::map<std::string, msRegister::base_creator_fn>& map=msRegister::registry();

 for( it = map.begin(); it!= map.end();++it) {

     std::cout<<"call registry in python of "<<it->first<<std::endl;
     it->second()->registryInPython();
     };
    
 boost::shared_ptr<msTreeMapper> treeMapper   =  msTreeMapper::New();
 boost::shared_ptr<msUnitsManager> unitMng0   =  msUnitsManager::New();
 boost::shared_ptr<msUnitsManager> unitMng1   =  msUnitsManager::New();
 boost::shared_ptr<msUnitsManager> unitMng2   =  msUnitsManager::New();

 unitMng0->setId("unitm");
 unitMng1->set("Angstrom"); unitMng1->setId("unitAngstrom");
 unitMng2->set("Bohr");     unitMng2->setId("unitBohr");

 treeMapper->addChild(unitMng0 , "unitMng0" );
 treeMapper->addChild(unitMng1 , "unitMng1" );
 treeMapper->addChild(unitMng2 , "unitMng2" );

 cout<<*treeMapper<<endl;
 
 boost::shared_ptr<msUnitsManager> unit = boost::static_pointer_cast<msUnitsManager>( treeMapper->getChild("unitAngstrom") );
 cout<<*unit<<endl;
 
 msTreeMapper::childIterator it2 = treeMapper->firstChildOfType("msUnitsManager");

 for( ; it2 != treeMapper->endChildren() ; it2=treeMapper->nextChildOfSameType(it2) ) {

     msChild<msTreeMapper>& ref = (*it2).second; 
     cout<<*ref<<endl;
     }
     
 
 boost::shared_ptr<msTreeMapper> treeMapper2 = treeMapper->clone();
 
 cout<<*treeMapper2<<endl;
 unitMng0->set("Bohr");
 cout<<*treeMapper2<<endl;
 cout<<*treeMapper<<endl; 
 return 0;
 }


